﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DARE
{
    [AttrTypeDependentSerializable(typeof(CSphereEmitter))]
    public class CSphereEmitter: AEmitter
    {
        #region properties

        public float Ray { get; set; }
        public bool EdgeSpawn { get; set; }

        #endregion

        #region ctor

        public CSphereEmitter(string name)
            :base(name)
        {

        }

        #endregion

        #region methods

        public override AEmitter Clone()
        {
            CSphereEmitter pe = new CSphereEmitter(Name);
            pe.EmissionInterval = EmissionInterval;
            pe.EmitPerEmission = EmitPerEmission;
            pe.MaxParticlesSimultaneous = MaxParticlesSimultaneous;
            pe.ReferenceParticle = ReferenceParticle;
            pe.Ray = Ray;
            pe.EdgeSpawn = EdgeSpawn;
            return pe;
        }

        public override void GetParametersFromEmitter(IParticle particle)
        {
            float ray = Ray;
            if (!EdgeSpawn)
                ray = CDare.Instance.Random.Next((int)(ray * 1000)) / 1000.0f;
            Vector3 posOff = m_node.Position;
            Vector3 pointPos = Vector3.Transform(new Vector3(ray, 0, 0), Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), CDare.Instance.Random.Next(36000) / 100.0f));
            pointPos = Vector3.Transform(pointPos, Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), CDare.Instance.Random.Next(36000) / 100.0f));
            pointPos = Vector3.Transform(pointPos, Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), CDare.Instance.Random.Next(36000) / 100.0f));

            particle.Position = new Vector3(posOff.X + pointPos.X, posOff.Y + pointPos.Y, posOff.Z + pointPos.Z);

            Vector3 vec = Vector3.Normalize(particle.Position - m_node.Position);

            Vector3 dir = vec * Velocities;

            particle.Velocities = dir;
        }
        #endregion
    }
}
